<?php
error_reporting(E_ALL ^ E_NOTICE);

require_once ('../../api/classes/gbif.checklist-1-1.php');
require_once ('../../api/classes/gbif.custom-eml.php');

$template = trim($_REQUEST['template']);
$template = ($template == '') ? '../../templates/Merged-Checklist/checklist-1.1.xlsx' : $template;

$folder = './files/';
$tplObj = new Checklist11($template);

$version = $tplObj->getVersion();


// # Make CSV file
// $tplObj->saveFile($folder . 'checklist.csv',2,'CSV');
// die('<br>File Created');

# Make EML
$eml = new CustomEml();
$sheet = $tplObj->getSheet(1);
$eml->createEmlFromWorksheet( $sheet );
$eml->generateXml(0);
$xml = $eml->getRawXml();
file_put_contents($folder . 'eml.xml', $xml );

# Make Checklist
$tplObj->validateChecklistData();

$tplObj->writeChecklistData($folder);

# Make metaxml
file_put_contents($folder . 'meta.xml', $tplObj->meta->generateMetaData( $tplObj->getIndexes(), $tplObj->getFilenames() ) );

$files = array_merge( array('eml.xml', 'meta.xml'), $tplObj->getFilenames() );
$tplObj->zipArchive($folder . 'dwca-tpl1.zip', $folder, $files );
?>
<html><style type="text/css">
<!--
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 14px;
}
body {
	margin-left: 10px;
	margin-top: 10px;
}
-->
</style><title>Checklist Template 1</title>
	<body link="#009900" vlink="#009900" alink="#009900">
		
		<h2>Checklist Template 1</h2>
<?php
	print 'File Name: ' . $template;
	print '<br>File Version: ' . $version;
	print '<p>Generated Darwin Core Archive: <a href="' . $folder . 'dwca-tpl1.zip' . '">dwca-tpl1.zip</a></p>';
?>
	</body>
</html>